package View;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;

import Controller.ControladorCategoria;
import Model.Category;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class ActualizarCategoria extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textNombre;
	private JTextArea textArea;
	private Category cat;

	/**
	 * Launch the application.
	 */
	/**
	 * Create the frame.
	 * @param category 
	 */
	public ActualizarCategoria(Category category) {
		this.cat = category;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JPanel panel = new JPanel();
		panel.setBounds(10, 11, 414, 240);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBounds(227, 11, 1, 1);
		panel_1.setLayout(null);
		panel.add(panel_1);
		
		JLabel label = new JLabel("Nombre");
		label.setBounds(58, 30, 46, 14);
		panel_1.add(label);
		
		JLabel label_1 = new JLabel("Descripcion");
		label_1.setBounds(58, 55, 65, 14);
		panel_1.add(label_1);
		
		textField = new JTextField();
		textField.setColumns(10);
		textField.setBounds(127, 27, 204, 20);
		panel_1.add(textField);
		
		JButton button = new JButton("Add");
		button.setBounds(57, 176, 72, 23);
		panel_1.add(button);
		
		JTextArea textArea = new JTextArea();
		textArea.setBounds(127, 56, 204, 59);
		panel_1.add(textArea);
		
		JButton button_1 = new JButton("Close");
		button_1.setBounds(151, 176, 71, 23);
		panel_1.add(button_1);
		
		JLabel label_2 = new JLabel("Nombre");
		label_2.setBounds(66, 42, 46, 14);
		panel.add(label_2);
		
		textNombre = new JTextField();
		textNombre.setColumns(10);
	
		textNombre.setText(cat.getNombreC());
		
		textNombre.setBounds(135, 39, 204, 20);
		panel.add(textNombre);
		
		final JTextArea textDesc = new JTextArea();
		
		textDesc.setText(cat.getDescripcion());
		
		textDesc.setBounds(135, 68, 204, 59);
		panel.add(textDesc);
		
		JLabel label_3 = new JLabel("Descripcion");
		label_3.setBounds(66, 67, 65, 14);
		panel.add(label_3);
		
		JButton button_3 = new JButton("Close");
		button_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ActualizarCategoria.this.dispose();
			}
		});
		button_3.setBounds(159, 188, 71, 23);
		panel.add(button_3);
		
		JButton btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
			cat.setNombreC(textNombre.getText());
			cat.setDescripcion(textDesc.getText());
			ControladorCategoria controladorCategoria = new ControladorCategoria();
			controladorCategoria.Actualizar(cat);
			ActualizarCategoria.this.dispose();
			}
		});
		btnSave.setBounds(60, 188, 65, 23);
		panel.add(btnSave);
	}
}
